package com.fzy.designpattern.observer.jdk;

import java.util.Observable;
import java.util.Observer;

/**
 * 实现观察者
 *
 * @author 冯赵杨
 * @create 2018/9/12
 */
public class MyObserver implements Observer {

    /**
     * This method is called whenever the observed object is changed. An
     * application calls an <tt>Observable</tt> object's
     * <code>notifyObservers</code> method to have all the object's
     * observers notified of the change.
     *
     * @param o   the observable object.
     * @param arg an argument passed to the <code>notifyObservers</code>
     */
    @Override
    public void update(Observable o, Object arg) {
        int state = ((ConcreteSubject) o).getState();

        System.out.println("state=" + state);
    }
}
